<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="网络议政"></uni-navbar></view>

		<u-tabs class="tabs" :list="list" :is-scroll="false" :current="filterType" @change="change"></u-tabs>
		<block v-if="filterType == 0">
			<view class="tab_list">
				<view class="tab_view" v-for="(item, index) in issueList" :key="item.id" @click="navTo('/pagesA/discussion/detail?id=' + item.id)">
					<view class="a_con">
						<view class="a_con_tit">{{ item.issue }}</view>
						<view class="a_con_status">
							<image class="status_img" :src="$imagePreview(item.proposerTouxiang)" mode="aspectFill"></image>
							<text class="status_name">{{ item.proposerName }}</text>
							<text class="status_lb">{{ item.jiebie }}</text>
							<text class="status_node st_end" v-if="item.nodeStatus == 2">已结束</text>
							<text class="status_node st_tlz" v-else>讨论中</text>
							<text class="status_node st_gly" v-if="item.isVisible == 0">仅管理员可见</text>
						</view>
					</view>
					<view class="a_tlz">
						<view class="a_tlz_p">
							<text class="a_tlz_name">{{ item.groupName }}</text>
							<text class="a_tlz_time">{{ $parseTime(item.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</text>
						</view>
					</view>
				</view>
				<u-loadmore :status="loading" />
			</view>

			<view class="uploader-add" @click="navTo('/pagesA/discussion/add')"><u-icon name="plus" color="#fff" size="40"></u-icon></view>
		</block>
		<block v-else>
			<view class="tab_list">
				<view class="tab_view" v-for="(item, index) in groupList" :key="item.id">
					<view class="a_group" @click="navTo('/pagesA/discussion/group_detail?id=' + item.id)">
						<view class="a_img" v-if="item.logoPath"><image :src="$imagePathLogo(item.logoPath, 'default@2x.png')" mode="aspectFill"></image></view>
						<view class="a_img" v-else :style="'background-color:' + item.logoColor">{{ item.groupName.slice(0, 4) }}</view>
						<view class="a_name clamp">{{ item.groupName }}</view>
					</view>
				</view>
				<u-loadmore :status="loading" />
			</view>
		</block>

		<u-back-top :scroll-top="scrollTop" top="200"></u-back-top>

		<view v-if="false && issueList && groupList"></view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			scrollTop: 0,
			list: [
				{
					name: '网络议政'
				},
				{
					name: '我的讨论组'
				}
			],
			colorMap: {
				1: '#303133',
				2: '#0099ff',
				3: '#ff9900',
				9: '#19be6b'
			},
			filterType: 0,
			keyword: '',
			issueList: [],
			groupList: [],

			wlyzIssue: {
				groupName: '',
				status: 1
			},
			wlyzGroup: {
				groupName: '',
				status: 1
			},
			loading: 'loadmore'
		};
	},
	onLoad() {
		this.loadLogin();
		this.loadData('refresh');
	},
	onPullDownRefresh() {
		this.loadLogin();
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		change(e) {
			this.filterType = e;
			this.pageNum = 1;
			this.loadData('refresh');
		},
		loadLogin() {
			if (this.userInfo.sysUser) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
				this.roleCodes = this.userInfo.roleCodes.join(',');
				this.userName = this.userInfo.sysUser.userName;

				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}

			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				clientCode: this.clientCode,
				currentUserId: this.userId
			};
			if (this.filterType == 0) {
				data.wlyzIssue = this.wlyzIssue;
				this.$request('/wlyz/issue/list', data, {
					load: true
				}).then((res) => {
					let count = 0;
					if (type != 'add') {
						uni.stopPullDownRefresh();
						this.issueList = [];
					}
					this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
					this.pageNum = this.pageNum + 1;
					this.issueList = this.issueList.concat(res.data.records);
					this.loaded = true;
					if (this.issueList.length <= 0) {
						this.loading = 'nodata';
					}
				});
			} else {
				data.wlyzGroup = this.wlyzGroup;
				this.$request('/wlyz/group/list', data, {
					load: true
				}).then((res) => {
					let count = 0;
					if (type != 'add') {
						uni.stopPullDownRefresh();
						this.groupList = [];
					}
					this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
					this.pageNum = this.pageNum + 1;
					this.groupList = this.groupList.concat(res.data.records);
					this.loaded = true;
					if (this.groupList.length <= 0) {
						this.loading = 'nodata';
					}
				});
			}
		},
		search(e) {
			this.keyword = e;
			this.loadData('refresh');
		},
		type(e) {
			this.filterType = e;
			this.loadData('refresh');
		},
		navTo(url) {
			uni.navigateTo({
				url: url
			});
		}
	}
};
</script>

<style lang="scss">
.list-box {
	margin-bottom: 30rpx;
	padding: 30rpx 30rpx 0;
	border-radius: 30rpx;
	background-color: #fff;
}

.tabs {
	position: absolute;
	left: 0;
	right: 0;
	border-bottom: 1rpx solid #f1f2f3;
}

.tab_list {
	padding-top: 80rpx;
	width: 100%;
	height: auto;

	.tab_view {
		width: 100%;
		padding: 34rpx 30rpx 26rpx;
		line-height: 1.4;
		border-bottom: 1rpx solid #f1f2f3;
		background-color: #fff;

		.a_con {
			color: #333333;

			.a_con_tit {
				font-size: 16px;
				width: 100%;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				overflow: hidden;
			}

			.a_con_status {
				display: flex;
				align-items: center;
				width: 100%;
				line-height: 50rpx;
				font-size: 14px;
				margin: 14rpx 0 18rpx;
				color: #999;

				.status_img {
					flex-shrink: 0;
					margin-right: 12rpx;
					width: 50rpx;
					height: 50rpx;
					border-radius: 50%;
					overflow: hidden;
					background-color: #f1f2f3;
				}

				.status_name {
					flex-shrink: 0;
					margin-right: 12rpx;
					font-size: 14px;
				}

				.status_lb {
					margin: 0 8rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					/* position: relative;
					top: 0.3rem; */
				}

				.status_node {
					flex-shrink: 0;
					margin-left: auto;
					padding: 8rpx 20rpx;
					font-size: 13px;
					line-height: 1;
				}
			}

			.a_con_content {
				font-size: 14px;
				color: #333333;
				width: 100%;
				display: none;
			}
		}

		.a_tlz {
			color: #999;
			/* text-align: right; */

			.a_tlz_p {
				font-size: 13px;

				.a_tlz_name {
					display: inline-block;
					margin-right: 40rpx;
				}
			}
		}

		.a_group {
			display: flex;
			align-items: center;
			/* padding: 0 15rpx; */
			font-size: 16px;

			.a_img {
				display: flex;
				align-items: center;
				justify-content: center;
				flex-shrink: 0;
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
				text-align: center;
				font-size: 14px;
				color: #ffffff;
				line-height: 1.2;
				background: #ff9900;

				image {
					width: 100rpx;
					height: 100rpx;
					border-radius: 50%;
				}
			}

			.a_name {
				padding-left: 26rpx;
				line-height: 1.2;
			}
		}
	}
}

.st_end {
	color: #999;
	border: 1rpx solid #999;
	border-radius: 10rpx;
}
.st_tlz {
	color: #ff0000;
	border: 1rpx solid #ff0000;
	border-radius: 10rpx;
}
.st_gly {
	margin-right: 10rpx;
	color: #ce1617;
	border: 1rpx solid #ce1617;
	border-radius: 10rpx;
}
</style>
